<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
        <el-col :span="18">
          <el-form-item label="学院" prop="deptId" :title="queryParams.deptName">
            <treeselect style="width: 250px;"
                        v-model="queryParams.deptId"
                        :options="deptOptions"
                        :show-count="true"
                        placeholder="请选择教学部门下的学院" />
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item style="margin-left: 26px">
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row>
      <div class="dashboard-editor-container">

        <panel-group @handleSetLineChartData="handleSetLineChartData" />

        <el-row style="background:#fff;padding:16px 16px 0;margin-bottom:32px;">
          <line-chart :chart-data="lineChartData" />
        </el-row>

        <el-row :gutter="32">
          <el-col :xs="24" :sm="24" :lg="8">
            <div class="chart-wrapper">
              <raddar-chart />
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8">
            <div class="chart-wrapper">
              <pie-chart />
            </div>
          </el-col>
          <el-col :xs="24" :sm="24" :lg="8">
            <div class="chart-wrapper">
              <bar-chart />
            </div>
          </el-col>
        </el-row>
      </div>

    </el-row>
  </div>

</template>

<script>
import {listStudent, getStudent, delStudent, addStudent, updateStudent} from "@/api/contest/tstudent";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getDicts} from '@/api/system/dict/data';
import {deptTreeSelect} from '@/api/system/user';

//echarts
import PanelGroup from '../../dashboard/PanelGroup';
import LineChart from '../../dashboard/LineChart';
import RaddarChart from '../../dashboard/RaddarChart';
import PieChart from '../../dashboard/PieChart';
import BarChart from '../../dashboard/BarChart';

const lineChartData = {
  newVisitis: {
    topPrize: [100, 120, 161, 134, 105, 160, 165],
    firstPrize: [120, 82, 91, 154, 162, 140, 145],
    secondPrize: [150, 60, 70, 45, 180, 200, 160],
    thirdPrize: [50, 70, 90, 120, 130, 90, 160],
    excellenceAward: [90, 100, 120, 80, 60, 50, 40]

  },

  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130]
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130]
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130]
  }
}


export default {
  name: "Tanalyze",
  dicts: ['teacher_post', 'sys_user_sex', 'sys_normal_disable', 'teacher_pro'],
  components: {
    Treeselect,
    PanelGroup,
    LineChart,
    RaddarChart,
    PieChart,
    BarChart
  },
  data() {
    return {
      //设置选择日期
      pickerOptions: {
        //disabled为函数，返回值为布尔值，
        disabledDate: (time) => {
          let minYear = new Date().getFullYear() - 30
          return time > Date.now() || time.getTime() < new Date(JSON.stringify(minYear))
        }
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 学生信息表格数据
      studentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //树形选择学院列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        stuNum: null,
        stuName: null,
        deptId: undefined,
        grade: null,
        stuClass: null,
        gender: null,
        category: null,
        idNumber: null,
        phoneNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},

      //echarts
      lineChartData: lineChartData.newVisitis
    };
  },
  created() {
    this.getList();
    this.getDict();
  },
  methods: {
    /** 查询学生信息列表 */
    getList() {
      this.loading = true;
      listStudent(this.queryParams).then(response => {
          this.studentList = response.rows;
          this.total = response.total;
          this.loading = false;
          console.log(response.rows)
        },
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        stuId: null,
        stuNum: null,
        stuName: null,
        deptId: null,
        grade: null,
        stuClass: null,
        gender: null,
        category: null,
        idNumber: null,
        phoneNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.stuId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加学生信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const stuId = row.stuId || this.ids
      getStudent(stuId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改学生管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.stuId != null) {
            updateStudent(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addStudent(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const stuIds = row.stuId || this.ids;
      this.$modal.confirm('是否确认删除学生信息编号为"' + stuIds + '"的数据项？').then(function () {
        return delStudent(stuIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('contest/student/export', {
        ...this.queryParams
      }, `student_${new Date().getTime()}.xlsx`)
    },
    /**获取字典数据*/
    getDict() {
      getDicts('sys_user_sex').then(resp => {
        this.sexDict = resp.data
      })
      getDicts('teacher_pro').then(resp => {
        this.teacher_pro = resp.data
      })
      getDicts('teacher_post').then(resp => {
        this.teacher_post = resp.data
      })
      deptTreeSelect().then(response => {
        this.deptOptions = response.data;
        console.log("树形"+response.data)
      });
    },

  }
};
</script>

<style lang="scss" scoped>
.dashboard-editor-container {
  padding: 32px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 32px;
  }
}

@media (max-width:1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>

